<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQuery easyui demo</title>

<style type="text/css">
#user_fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
}
</style>


<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/color.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/demo/demo.css">
<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
	
	<table id="salesReturn_dg" class="easyui-datagrid" style="height: 900px;"
		url="salesReturn/findAll.do" toolbar="#salesReturn_toolbar" pagination="true"
		rownumbers="true" fitColumns="true" singleSelect="true"
		data-options="fit:false,border:false,pageSize:10,pageList:[10,20,30,40]">
		<thead>
			<tr>
				<th field="sno" width="50">销售出货单号</th>
				<th field="goodsNo" formatter="goodsFormat" width="50">商品名称</th>
				<th field="srQuantity" width="50">退货数量</th>
				<th field="srPrice" width="50">退货单价</th>
				<th field="srDate" width="50">退货日期</th>
				<th field="handler" width="50">经手人</th>
				<th field="clientNo" formatter="clientFormat" width="50">客户名称</th>
				<th field="srRemark" width="50">销售退货备注</th>
				<th field="storageNo" formatter="storageFormat" width="50">仓库名称</th>
			</tr>
		</thead>
	</table>
	
	<div id="salesReturn_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newSalesReturn()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editSalesReturn()">编辑</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroySalesReturn()">删除</a>
	</div>

	<div id="salesReturn_dlg" class="easyui-dialog" style="padding: 10px 20px"
		closed="true" buttons="#salesReturn_dlg-buttons">
		<div class="ftitle">详细信息</div>
		<form id="salesReturn_fm" method="post" novalidate>			  
			<div class="fitem">
				<label>商品名称:</label> <input id="id_goodss" name="goods.goodsNo" class="easyui-combobox"
					url="goods/findList.do" valueField="goodsNo" textField="goodsName" required="true"
					editable="false">
			</div>
			<div class="fitem">
				<label>退货数量:</label> <input name="srQuantity" class="easyui-textbox">
			</div>
			<div class="fitem">
				<label>退货单价:</label> <input name="srPrice" class="easyui-textbox">
			</div>
			<div class="fitem">
				<label>退货日期:</label> <input name="srDate" class="easyui-datebox">
			</div>
			<div class="fitem">
				<label>经手人:</label> <input name="handler" class="easyui-textbox">
			</div>
			<div class="fitem">
				<label>客户名称:</label> <input id="id_clientt"  name="client.clientNo"
					url="client/findList.do" valueField="clientNo"
					textField="client" required="true" editable="false"
					class="easyui-combobox">
			</div>
			<div class="fitem">
				<label>销售退货备注:</label> <input name="srRemark" class="easyui-textbox">
			</div>
		    <div class="fitem">
				<label>仓库名称:</label> <input id="id_storagee"  name="storage.storageNo"
					url="storage/findList.do" valueField="storageNo"
					textField="storageName" required="true" editable="false"
					class="easyui-combobox">
			</div>
		
		</form>
	</div>
	
	<div id="salesReturn_dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveSalesReturn()" style="width: 90px">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#salesReturn_dlg').dialog('close')"
			style="width: 90px">取消</a>
	</div>
	<script type="text/javascript">	
	$.fn.datebox.defaults.formatter = function(date){
		var y = date.getFullYear();
		var m = date.getMonth()+1;
		var d = date.getDate();
		return y+'/'+m+'/'+d;
	}
	
	$.fn.datebox.defaults.parser = function(date){
		if(date){
			return  new Date(date)
		}else{
			return new Date();
		}
	}

		//使用格式化显示数据
		function goodsFormat(value, row, rowindex) {
			return row.goods.goodsName;
		}
	
		function clientFormat(value, row, rowindex) {
			return row.client.client;
		}
	
		function storageFormat(value, row, rowindex) {
			return row.storage.storageName;
		}
	
		var url;
		function newSalesReturn() {
			$('#salesReturn_dlg').dialog('open').dialog('setTitle', '新增');
			$('#salesReturn_fm').form('clear'); //清除表单数据
			url = 'salesReturn/addSalesReturn.do'; //按新增 调用的网址
			
			//从已经加载的datagride中所选择的行（row）中获取key值,修改下拉框的选中值  
			var goodsdata = $('#id_goodss').combobox('getData');
		    if(goodsdata.length>0){
			  $('#id_goodss').combobox('select',goodsdata[0].goodsNo);
		    }; 
		    
		    var clientdata = $('#id_clientt').combobox('getData');
		    if(clientdata.length>0){
			  $('#id_clientt').combobox('select',clientdata[0].clientNo);
		    }; 	
		    
		    var storagedata = $('#id_storagee').combobox('getData');
		    if(storagedata.length>0){
			  $('#id_storagee').combobox('select',storagedata[0].storageNo);
		    }; 	
		}
		
		function editSalesReturn() {
			var row = $('#salesReturn_dg').datagrid('getSelected');
			if (row) {
				$('#salesReturn_dlg').dialog('open').dialog('setTitle', '编辑'); //打开对话框
				$('#salesReturn_fm').form('clear');   //清除表单数据
				$('#salesReturn_fm').form('load', row);  //重新加载数据
				url = 'salesReturn/updateSalesReturn.do?sno=' + row.sno;
				
				//console.log(row.provider.providerNo);
				//从已经加载的datagride中所选择的行（row）中获取key值,修改下拉框的选中值 
			    
			    var goodsdata = $('#id_goodss').combobox('getData');
			    if(goodsdata.length>0){
				  $('#id_goodss').combobox('select',row.goods.goodsNo);
			    }; 
			    
			    var clientdata = $('#id_clientt').combobox('getData');
			    if(clientdata.length>0){
				  $('#id_clientt').combobox('select',row.client.clientNo);
			    }; 	
			    
			    var storagedata = $('#id_storagee').combobox('getData');
			    if(storagedata.length>0){
				  $('#id_storagee').combobox('select',row.storage.storageNo);
			    }; 	
			}
		}
		function saveSalesReturn() {
			$('#salesReturn_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$('#salesReturn_dlg').dialog('close'); // close the dialog
						$('#salesReturn_dg').datagrid('reload'); // reload the user data
					}
				}
			});
		}
		function destroySalesReturn() {
			var row = $('#salesReturn_dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm', '确定要删除吗?', function(r) {
					if (r) {   //ajax调用-异步通信调用
						$.post('salesReturn/deleteSalesReturn.do', {
							sno : row.sno
						}, function(result) {
							if (result.success) {
								$('#salesReturn_dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show({ // show error message
									title : 'Error',
									msg : result.errorMsg
								});
							}
						}, 'json');  //回调函数
					}
				});
			}
		}
	</script>


</body>
</html>